home *** CD-ROM | disk | FTP | other *** search
/ Adobe Graphics & Publishing SDK 1996 December / Adobe Graphics & Publishing SDK 1996 December.iso / mac / After Effects 3.1 SDK Mac / Examples / Effects Samples / Checkout / Checkout.c < prev   
Text File  |  1996-11-06  |  7KB  |  289 lines

  1. /**
  2.     Checkout.c
  3.     
  4.     Part of the Adobe After Effects 3.1 SDK.
  5.     (c) 1994-96, Adobe Systems Inc.
  6.     All Rights Reserved.
  7.  
  8.     This effect splits a layer in two. In the bottom half, it displays the
  9.     current layer at the current time. In the top half, it displays a user-
  10.     specifiable layer at a user-specifiable time.
  11.     
  12.     This demonstrates:
  13.         Using a Slider control.
  14.         Using a Layer control.
  15.         Checking out parameters at times other than the current time.
  16.         Using the PF_COPY callback routines.
  17.         
  18.     Revision History
  19.         1.0, Created by dmw, 13 Jan 94
  20.         1.1, Mac/PowerMac version, dmw, 13 Oct 94
  21.         2.0, Updated for AE 3.0, dmw, 18 Oct 95
  22.         2.1, Added call to AEFX_CLR_STRUCT macro to clear out PF_ParamDef, ba, 6 Nov 96
  23. **/
  24.  
  25. #include "AE_EffectCB.h"
  26. #include "AE_Macros.h"
  27. #include <A4Stuff.h>
  28.  
  29. /**
  30.  ** Here we #define our version values for use in the PF_VERSION
  31.  ** macro. After Effects uses these values to determine which
  32.  ** plug-in to run if it finds multiple version of the same effect
  33.  ** on the user's drive.
  34.  **/
  35. #define    MAJOR_VERSION    2
  36. #define    MINOR_VERSION    0
  37. #define    BUG_VERSION        0
  38. #define    STAGE_VERSION    PF_Stage_RELEASE
  39. #define    BUILD_VERSION    0
  40.  
  41.  
  42. /**
  43.  ** Some more useful #define's
  44.  **
  45.  **/
  46. #define    NAME                "Checkout"
  47. #define DESCRIPTION            \
  48. "Demonstrates checking out layers at other times. (c) 1994-96 Adobe Systems Inc."
  49.  
  50.  
  51. /** Parameter Definition Constants
  52.  
  53.     Here we define the parameters, their default
  54.     settings, and minimum and maximum values.
  55.  
  56. **/
  57.  
  58. enum {
  59.     CHECK_INPUT = 0,
  60.     CHECK_FRAME,
  61.     CHECK_LAYER,
  62.     
  63.     CHECK_NUM_PARAMS
  64. };
  65.  
  66. #define    CHECK_FRAME_MIN        0
  67. #define    CHECK_FRAME_MAX        100
  68. #define    CHECK_FRAME_DFLT    0
  69.  
  70.  
  71. /** Command Specific Subroutines
  72.  
  73.     This plug-in only deals with the commands:
  74.         PF_Cmd_ABOUT
  75.         PF_Cmd_GLOBAL_SETUP
  76.         PF_Cmd_PARAMS_SETUP
  77.         PF_Cmd_RENDER
  78.     All other commands are ignored.  There is a routine for
  79.     each command, and a main routine to dispatch at the bottom.
  80.  
  81.     There is no PF_Cmd_GLOBAL_SETDOWN because I don't allocate
  82.     any memory in GLOBAL_SETUP, so I don't have any cleanup to do.
  83.     
  84. **/
  85.  
  86. static PF_Err About (
  87.     PF_InData        *in_data,
  88.     PF_OutData        *out_data,
  89.     PF_ParamDef        *params[],
  90.     PF_LayerDef        *output )
  91. {
  92.     PF_SPRINTF(out_data->return_msg,
  93.         "%s, v%d.%d\r" DESCRIPTION ,
  94.         NAME, MAJOR_VERSION, MINOR_VERSION);
  95.  
  96.     return PF_Err_NONE;
  97. }
  98.  
  99.  
  100. static PF_Err GlobalSetup (
  101.     PF_InData        *in_data,
  102.     PF_OutData        *out_data,
  103.     PF_ParamDef        *params[],
  104.     PF_LayerDef        *output ) 
  105. {
  106.     PF_Err     err = PF_Err_NONE;
  107.     
  108.     /* Need to let AE know what version of the "Checkout" plug-in
  109.      * we are.
  110.      */
  111.     out_data->my_version = PF_VERSION(MAJOR_VERSION, MINOR_VERSION,
  112.                                     BUG_VERSION, STAGE_VERSION, BUILD_VERSION);
  113.  
  114.     /* This effect checks out parameters at times other than the current time,
  115.      * so I let AE know this by setting the PF_OutFlag_WIDE_TIME_INPUT flag.
  116.      */
  117.     out_data->out_flags |= PF_OutFlag_WIDE_TIME_INPUT;
  118.     
  119.     return err;
  120. }
  121.  
  122.  
  123. static PF_Err ParamsSetup (
  124.     PF_InData        *in_data,
  125.     PF_OutData        *out_data,
  126.     PF_ParamDef        *params[],
  127.     PF_LayerDef        *output )
  128. {
  129.     PF_Err            err = PF_Err_NONE;
  130.     PF_ParamDef        def;    /* scratch space for a parameter definition */
  131.  
  132.     /* Always clear out the PF_ParamDef structure before adding your parameters,
  133.      * this macro will do that.
  134.      */
  135.     AEFX_CLR_STRUCT(def);
  136.     
  137.     /* Create the SLIDER parameter... */
  138.  
  139.     def.param_type = PF_Param_SLIDER;
  140.     PF_STRCPY(def.name, "Time to checkout");
  141.  
  142.     /* NOTE: we must set these strings to empty strings to prevent
  143.      * garbage text from being displayed above our sliders...
  144.      */
  145.     def.u.sd.value_str[0] = '\0';
  146.     def.u.sd.value_desc[0] = '\0';
  147.  
  148.     /* The min and max values of the slider and the min and max
  149.      * values the user can type will be the same value...
  150.      */
  151.     def.u.sd.valid_min = def.u.sd.slider_min = CHECK_FRAME_MIN;
  152.     def.u.sd.valid_max = def.u.sd.slider_max = CHECK_FRAME_MAX;
  153.     def.u.sd.value = def.u.sd.dephault = 0;
  154.     if (err = PF_ADD_PARAM(in_data, -1, &def)) return err;
  155.     
  156.     /* Create the LAYER parameter... */
  157.  
  158.     def.param_type = PF_Param_LAYER;
  159.     PF_STRCPY(def.name, "Layer to checkout");
  160.     
  161.     /* make the default layer setting to be "none." Could also make it
  162.      * PF_LayerDefault_MYSELF
  163.      */
  164.     def.u.ld.dephault = PF_LayerDefault_NONE;
  165.     
  166.     if (err = PF_ADD_PARAM(in_data, -1, &def)) return err;
  167.  
  168.     /* Set number of parameters before leaving */
  169.  
  170.     out_data->num_params = CHECK_NUM_PARAMS;
  171.  
  172.     return err;
  173. }
  174.  
  175.  
  176. /** Render
  177.  ** 
  178.  **/
  179.  
  180. static PF_Err Render(
  181.     PF_InData        *in_data,
  182.     PF_OutData        *out_data,
  183.     PF_ParamDef        *params[],
  184.     PF_LayerDef        *output )
  185. {
  186.     PF_Err            err = PF_Err_NONE;
  187.     PF_Err            err2;
  188.     long            frame;
  189.     Rect            halfsies;
  190.  
  191.     PF_ParamDef        checkout;        /* put the ParamDef on the stack; will be checking one out later */
  192.  
  193.     /* set the halfsies rectangle to be the top half of the layer */
  194.     
  195.     halfsies.top = halfsies.left = 0;
  196.     halfsies.right = output->width;
  197.     halfsies.bottom = output->height / 2;
  198.     
  199.     /* frame is the slider value, an integer. I'll use this for the time value to
  200.      * check out a frame at (frame/30) seconds
  201.      */
  202.     frame = params[CHECK_FRAME]->u.sd.value;
  203.     
  204.     /* check out the parameter CHECK_LAYER at time (frame/30) seconds with a shutter
  205.      * duration of 0 and put it into the 'checkout' ParamDef
  206.      *
  207.      * If we want, we can check out CHECK_INPUT, or any other parameter. For example,
  208.      * to do a visual echo, we just check out CHECK_INPUT at (in_data->current_time -
  209.      * delay_time) and blend it in using the PF_BLEND callback.
  210.      */
  211.     err = PF_CHECKOUT_PARAM(in_data, CHECK_LAYER,
  212.                             frame, 0,
  213.                             30, &checkout);
  214.                             
  215.     if (!err) {
  216.         if (checkout.u.ld.data) {
  217.  
  218.             /* An actual valid layer. Copy the checked-out layer into the top half
  219.              * of the output buffer, squeezing or stretching it as needed.
  220.              */
  221.             err = PF_COPY(&checkout.u.ld, output, NULL, &halfsies);
  222.  
  223.         } else {
  224.  
  225.             /* checkout.u.ld.data is NULL, meaning that the 'NONE' layer was selected.
  226.              * In this case, I'll fill the top half with zero-alpha black (send NULL
  227.              * for the color.)
  228.              */
  229.             err = PF_FILL(NULL, &halfsies, output);
  230.         }
  231.     
  232.         if (!err) {
  233.             halfsies.top = halfsies.bottom;
  234.             halfsies.bottom = output->height;
  235.  
  236.             /* Set the 'halfsies' rectangle to be the bottom half and copy the
  237.              * source layer into the bottom half, squeezing or stretching it as needed.
  238.              */
  239.             err = PF_COPY(¶ms[CHECK_INPUT]->u.ld, output, NULL, &halfsies);
  240.         
  241.         }
  242.     
  243.         /* Note that I'm checking in the 'checkout' param even if an error has occurred
  244.          * since the checkout. It is very important to check in all parameters you've checked
  245.          * out. (Errors are not necessarily something bad... a user cancel is sent back
  246.          * from the PF callbacks as an error.) Be careful to respond to all the error codes
  247.          * sent back from PF routines -- interruptibility may be degraded otherwise.
  248.          */
  249.         err2 = PF_CHECKIN_PARAM(in_data, &checkout);
  250.         if (!err) err = err2;
  251.     }
  252.  
  253.     return err;
  254. }
  255.  
  256.  
  257. PF_Err main (
  258.     PF_Cmd            cmd,
  259.     PF_InData        *in_data,
  260.     PF_OutData        *out_data,
  261.     PF_ParamDef        *params[],
  262.     PF_LayerDef        *output )
  263. {
  264.     PF_Err        err = PF_Err_NONE;
  265.     EnterCodeResource();            /* only available in CodeWarrior */
  266.     
  267.     switch (cmd) {
  268.         case PF_Cmd_ABOUT:
  269.             err = About(in_data,out_data,params,output);
  270.             break;
  271.         case PF_Cmd_GLOBAL_SETUP:
  272.             err = GlobalSetup(in_data,out_data,params,output);
  273.             break;
  274.         case PF_Cmd_PARAMS_SETUP:
  275.             err = ParamsSetup(in_data,out_data,params,output);
  276.             break;
  277.         case PF_Cmd_RENDER:
  278.             err = Render(in_data,out_data,params,output);
  279.             break;
  280.         
  281.         default:
  282.             break;
  283.     }
  284.     
  285.     ExitCodeResource();
  286.     
  287.     return err;
  288. }
  289.